package com.toman.ui.work.workshop;

import android.app.Dialog;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.NavigationRes;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.itheima.pulltorefreshlib.PullToRefreshBase;
import com.itheima.pulltorefreshlib.PullToRefreshScrollView;
import com.lzy.okhttputils.OkHttpUtils;
import com.lzy.okhttputils.callback.StringCallback;
import com.lzy.okhttputils.request.GetRequest;
import com.toman.Enum.BaseEnum;
import com.toman.Enum.NetworkEnum;
import com.toman.Enum.PermEnum;
import com.toman.Interfaces.NewBaseUrl;
import com.toman.JavaBean.CombineEntity;
import com.toman.JavaBean.ReceiveSendworkOrderDto;
import com.toman.JavaBean.StaticsCount;
import com.toman.R;
import com.toman.Util.ActionCallback;
import com.toman.Util.BaseNetUtil;
import com.toman.Util.DialogUtils;
import com.toman.Util.IntentUtils;
import com.toman.Util.JsonExcludeNull;
import com.toman.Util.StringUtils;
import com.toman.Util.ToastUtil;
import com.toman.Util.ViewUtil;
import com.toman.bean.DialogBean;
import com.toman.toolbar.ToolBarActivity;
import com.toman.widget.ClearEditText;
import com.toman.widget.callback.StringLoadingCallback;
import com.zhy.adapter.recyclerview.CommonAdapter;
import com.zhy.adapter.recyclerview.MultiItemTypeAdapter;
import com.zhy.adapter.recyclerview.base.ViewHolder;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import okhttp3.Request;
import okhttp3.Response;

import static com.toman.Interfaces.NewBaseUrl.workshop_submit_delete;

public class SubmitActivity extends ToolBarActivity {

    @BindView(R.id.et_search)
    ClearEditText etSearch;
    @BindView(R.id.tv_select)
    TextView tvSelect;
    @BindView(R.id.fl_et)
    RelativeLayout flEt;
    @BindView(R.id.tv_select0)
    TextView tvSelect0;
    @BindView(R.id.iv_select0)
    ImageView ivSelect0;
    @BindView(R.id.rl_select0)
    RelativeLayout rlSelect0;
    @BindView(R.id.tv_select1)
    TextView tvSelect1;
    @BindView(R.id.iv_select1)
    ImageView ivSelect1;
    @BindView(R.id.rl_select1)
    RelativeLayout rlSelect1;
    @BindView(R.id.tv_select2)
    TextView tvSelect2;
    @BindView(R.id.iv_select2)
    ImageView ivSelect2;
    @BindView(R.id.rl_select2)
    RelativeLayout rlSelect2;
    @BindView(R.id.ll_base)
    LinearLayout llBase;
    @BindView(R.id.cb_muti)
    CheckBox cbMuti;
    @BindView(R.id.btn_muti)
    Button btnMuti;
    @BindView(R.id.rl_muti)
    RelativeLayout rlMuti;
    @BindView(R.id.lv)
    RecyclerView lv;
    @BindView(R.id.mPullToRefreshScrollView)
    PullToRefreshScrollView mPullToRefreshScrollView;
    @BindView(R.id.mMangeNodata)
    TextView mMangeNodata;
    int page = 2;
    private List<ReceiveSendworkOrderDto> list = new ArrayList<>();
    private List<CombineEntity> list2 = new ArrayList<>();

    Dialog dialog;
    private String receiveStatus = "1";
    private String auditStatus = "";
    private String isfirstReport = "";//1表示查询首件报工信息,0表示查询量产报工信息
    private String sendworkId = null;//总派工单ID,派工信息Tab页中查看报工信息使用
    private String mappingId = null;//子派工单ID,领取派工单Tab页中查看报工信息使用

    CommonAdapter<ReceiveSendworkOrderDto> adapter;
    CommonAdapter<CombineEntity> adapter2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_submit);
        ButterKnife.bind(this);
        initToolBar(BaseEnum.SUBMIT.name);
        initView();
        initIntent();
    }

    private void initIntent() {
        isfirstReport = getIntent().getStringExtra("isfirstReport");
        if (StringUtils.isNotEmpty(getIntent().getStringExtra("sendworkId"))){
            sendworkId = getIntent().getStringExtra("sendworkId");
        }
        if (StringUtils.isNotEmpty(getIntent().getStringExtra("mappingId"))){
            mappingId = getIntent().getStringExtra("mappingId");
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        if (!StringUtils.isEmpty(getIntent().getStringExtra("status"))){
            p_id=(getIntent().getStringExtra("etSearch"));
            setStatus(getIntent().getStringExtra("status"));
        } else {
            customer(1, 1, etSearch.getText().toString());
        }

    }


    private void initView() {
        initAdapter();
        etSearch.setHint("派工单号/品号/品名");


        cbMuti.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {

                for (int i = 0; i < list.size(); i++) {
                    list.get(i).setCheckStatus(b);
                }


                adapter.notifyDataSetChanged();
            }
        });
        rlMuti.setVisibility(View.GONE);

        adapter.setOnItemClickListener(new MultiItemTypeAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View view, RecyclerView.ViewHolder holder, int position) {
                List<ReceiveSendworkOrderDto> beanlist = adapter.getDatas();
                ReceiveSendworkOrderDto bean = beanlist.get(position);
                Bundle bundle = new Bundle();

                bundle.putSerializable("bean", bean);
                bundle.putString("status", receiveStatus);
                IntentUtils.startActivity(SubmitActivity.this, GetInfActivity.class, bundle);

            }

            @Override
            public boolean onItemLongClick(View view, RecyclerView.ViewHolder holder, int position) {
                return false;
            }
        });

        adapter2.setOnItemClickListener(new MultiItemTypeAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View view, RecyclerView.ViewHolder holder, int position) {
                List<CombineEntity> beanlist = adapter2.getDatas();
                CombineEntity bean = beanlist.get(position);
                Bundle bundle = new Bundle();
                bundle.putSerializable("bean", bean);
                bundle.putString("status", auditStatus);
                if (bean.getIsfirstReport() == 1) {
                    IntentUtils.startActivity(SubmitActivity.this, SubmitFirstInfActivity.class, bundle);
                } else {
                    IntentUtils.startActivity(SubmitActivity.this, SubmitMoreInfActivity.class, bundle);

                }

            }

            @Override
            public boolean onItemLongClick(View view, RecyclerView.ViewHolder holder, int position) {
                return false;
            }
        });
        lv.setAdapter(adapter);
//        LinearLayoutManager manager = new LinearLayoutManager(this);
//        lv.setLayoutManager(manager);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false) {
            @Override
            public boolean canScrollVertically() {
                return false;
            }
        };
        lv.setLayoutManager(linearLayoutManager);
        mPullToRefreshScrollView.setMode(PullToRefreshBase.Mode.BOTH);
        mPullToRefreshScrollView.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener2<ScrollView>() {
            @Override
            public void onPullDownToRefresh(PullToRefreshBase<ScrollView> refreshView) {
                dialog=null;
                dialogList.clear();
                p_id=null;

                //getHttp(1,1);
//                content1=content2=content3=content4=null;
                page = 2;
                customer(1, 1, etSearch.getText().toString().trim());


            }

            @Override
            public void onPullUpToRefresh(PullToRefreshBase<ScrollView> refreshView) {
                customer(page, 2, etSearch.getText().toString().trim());
                page += 1;
            }
        });
        etSearch.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                        customer(1, 1, s.toString().trim());
            }
        });
        etSearch.setOnEditorActionListener(new TextView.OnEditorActionListener() {

            public boolean onEditorAction(TextView v, int actionId, KeyEvent event)  {

                if (actionId==EditorInfo.IME_ACTION_SEND ||(event!=null&&event.getKeyCode()== KeyEvent.KEYCODE_ENTER))

                {
                    customer(1, 1, etSearch.getText().toString().trim());

                    return true;
                }
                return false;
            }
        });

    }

    private void initAdapter() {
        adapter = new CommonAdapter<ReceiveSendworkOrderDto>(this, R.layout.item_workshop_get2, list) {
            @Override
            protected void convert(ViewHolder holder, ReceiveSendworkOrderDto item, final int position) {
                holder.setText(R.id.tv_time, item.getSendworkorderEntity().getCreateTime());
                holder.setText(R.id.tv_code, item.getSendworkorderEntity().getSendworkCode());
                holder.setText(R.id.tv_no, item.getOperationorderEntity().getOrderName());
                holder.setText(R.id.tv_product_name, item.getProductEntity().getProductName());
                holder.setText(R.id.tv_dep, item.getPlanEntity().getPlanNum());
                holder.setText(R.id.tv_beltline, item.getBeltlineEntity().getBeltlineName());
                holder.setText(R.id.tv_need, item.getSendworkOrderMappingEntity().getWorkCount() + "");
                holder.setText(R.id.tv_dispatching, item.getSendworkorderEntity().getSendworkCount() + "");

//                派工单状态
                if (item.getSendworkorderEntity().getOrderStatus().equals("0")) {
                    if (item.isCanReport()) {
                        holder.getView(R.id.btn_submit_more).setVisibility(View.VISIBLE);
                        holder.getView(R.id.btn_submit_more).setOnClickListener(v -> {
                            Bundle bundle = new Bundle();
                            bundle.putSerializable("bean", item);
                            IntentUtils.startActivity(SubmitActivity.this, SubmitMoreActivity.class, bundle);
                        });
                        holder.getView(R.id.btn_submit_first).setVisibility(View.VISIBLE);
                        holder.getView(R.id.btn_submit_first).setOnClickListener(v -> {
                            Bundle bundle = new Bundle();
                            bundle.putSerializable("bean", item);
                            IntentUtils.startActivity(SubmitActivity.this, SubmitFirstActivity.class, bundle);
                        });
                    }
                    else {
                        holder.getView(R.id.btn_submit_first).setVisibility(View.GONE);
                        holder.getView(R.id.btn_submit_more).setVisibility(View.GONE);


                    }
//                    holder.getView(R.id.btn_del).setVisibility(View.VISIBLE);

                    holder.setImageResource(R.id.iv_status, R.mipmap.icon_jxz);
                } else if (item.getSendworkorderEntity().getOrderStatus().equals("1")) {
                    holder.getView(R.id.btn_submit_more).setVisibility(View.GONE);
                    holder.getView(R.id.btn_submit_first).setVisibility(View.GONE);
//                    holder.getView(R.id.btn_del).setVisibility(View.VISIBLE);
                    holder.setImageResource(R.id.iv_status, R.mipmap.icon_ztz);
                } else {
//                    holder.getView(R.id.btn_del).setVisibility(View.VISIBLE);
                    holder.getView(R.id.btn_submit_more).setVisibility(View.GONE);
                    holder.getView(R.id.btn_submit_first).setVisibility(View.GONE);
                    holder.setImageResource(R.id.iv_status, R.mipmap.icon_yjs);
                }
                //                权限管理
                ViewUtil.permission(getApplicationContext(), BaseEnum.GET.has(PermEnum.SUBMITFIRST), holder.getView(R.id.btn_submit_first));
                ViewUtil.permission(getApplicationContext(), BaseEnum.GET.has(PermEnum.SUBMITMORE), holder.getView(R.id.btn_submit_more));


            }
        };

        adapter2 = new CommonAdapter<CombineEntity>(this, R.layout.item_workshop_submit, list2) {
            @Override
            protected void convert(ViewHolder holder, CombineEntity item, final int position) {
                holder.setText(R.id.tv_code, item.getReportNum());
                holder.setText(R.id.tv_no, item.getCombineParentSendworkorderEntity().getOperationArtlineEntity().getArtlineName());
                holder.setText(R.id.tv_dep, item.getCombineParentSendworkorderEntity().getPlanEntity().getPlanNum());
                holder.setText(R.id.tv_beltline, item.getCombineChildSendworkMappingEntity().getBeltlineEntity().getBeltlineName());
                holder.setText(R.id.tv_product_name, item.getCombineParentSendworkorderEntity().getProductEntity().getProductName());

                holder.setOnClickListener(R.id.btn_del, new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Map<String, Object> map = new HashMap<>();
                        map.put("id", item.getId() + "");
                        map.put("isfirstReport", item.getIsfirstReport() + "");
                        BaseNetUtil.actionMapDialog(SubmitActivity.this, workshop_submit_delete, map, token, "删除" + BaseEnum.SUBMIT.name, new ActionCallback() {
                            @Override
                            public void run() {
                                customer(1, 1, etSearch.getText().toString());
                            }
                        });
                    }
                });
                try {

//                    首件报工
                    if (item.getIsfirstReport() == 1) {
                        holder.getView(R.id.btn_check).setOnClickListener(v -> BaseNetUtil.actionDialog(SubmitActivity.this, NewBaseUrl.workshop_submit_firstreport_verify, item.getId() + "", token, "审核" + BaseEnum.SUBMIT.name, () -> customer(1, 1, etSearch.getText().toString())));
                        holder.setText(R.id.tv_title_qualified, "是否合格");
                        holder.setText(R.id.tv_need, "1".equals(item.getReportStatus()) ? "合格" : "不合格");
                        holder.setTextColor(R.id.tv_title_qualified, getResources().getColor(R.color.tv_orange));
                        holder.setTextColor(R.id.tv_need, getResources().getColor(R.color.tv_orange));

                    } else {
                        holder.getView(R.id.btn_check).setOnClickListener(v -> {
                            Bundle bundle = new Bundle();
                            bundle.putSerializable("bean", item);
                            IntentUtils.startActivity(SubmitActivity.this, SubmitMoreChcekActivity.class, bundle);
                        });
//                        量产报工未审核
                        if ("0".equals(item.getAuditStatus())) {
                            holder.setText(R.id.tv_title_qualified, "提交合格数量");
                            holder.setText(R.id.tv_need, item.getCounts12().getQualifiedCount() + "");


                        }
//量产报工已审核
                        else {
                            holder.setText(R.id.tv_title_qualified, "审核合格数量");
                            holder.setText(R.id.tv_need, item.getCounts12().getVerifyQualifiedCount() + "");

                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
                holder.setText(R.id.tv_dispatching, item.getCombineParentSendworkorderEntity().getSendworkorderEntity().getSendworkCount() + "");
                holder.setText(R.id.tv_finish, item.getCombineParentSendworkorderEntity().getPerentCompleteCount().getCompletedCount() + "");
//                派工单状态
                try {
                    if (item.getCombineParentSendworkorderEntity().getSendworkorderEntity().getOrderStatus().equals("0")) {
                        holder.setImageResource(R.id.iv_status, R.mipmap.icon_jxz);
                    } else if (item.getCombineParentSendworkorderEntity().getSendworkorderEntity().getOrderStatus().equals("1")) {
                        holder.setImageResource(R.id.iv_status, R.mipmap.icon_ztz);
                    } else {
                        holder.getView(R.id.btn_del).setVisibility(View.VISIBLE);
                        holder.getView(R.id.btn_submit_more).setVisibility(View.GONE);
                        holder.getView(R.id.btn_submit_first).setVisibility(View.GONE);
                        holder.setImageResource(R.id.iv_status, R.mipmap.icon_yjs);
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }

                if (item.getAuditStatus().equals("0")) {
                    holder.setText(R.id.tv_time, item.getCreateTime());
                    holder.getView(R.id.btn_del).setVisibility(View.VISIBLE);
                    holder.getView(R.id.btn_check).setVisibility(View.VISIBLE);

                    holder.setText(R.id.tv_man_name, "报工人");
                    holder.setText(R.id.tv_man, item.getOpUser().getRealName());


                } else {
                    holder.setText(R.id.tv_time, item.getAuditTime());
                    holder.getView(R.id.btn_del).setVisibility(View.VISIBLE);
                    holder.getView(R.id.btn_check).setVisibility(View.GONE);
                    holder.setText(R.id.tv_man_name, "审核人");
                    holder.setText(R.id.tv_man, item.getAuditUser().getRealName());

                }
                ViewUtil.permission(getApplicationContext(), BaseEnum.SUBMIT.has(PermEnum.DELETE), holder.getView(R.id.btn_del));
                ViewUtil.permission(getApplicationContext(), BaseEnum.SUBMIT.has(PermEnum.CHECK), holder.getView(R.id.btn_check));
            }
        };
    }

    public void customer(Integer page, final Integer type, String search) {
        if (dialog != null) {
            dialog.dismiss();
        }


        if (receiveStatus.equals("1")) {
            getGet(page, type, search);
        } else {
            getList(page, type, search);
        }
    }

    //已领取
    private void getGet(Integer page, Integer type, String search) {
        GetRequest params = OkHttpUtils
                .get(NewBaseUrl.workshop_get_list)
//                .params("companyId", companyId)
                .params("token", token)
                .params("key", search)
                .params("limit", NewBaseUrl.num).params("page", page.toString())
                .params("receiveStatus", receiveStatus)
                .params("queryReportCount", "1")
                .params("sendworkId",sendworkId)
                .params("mappingId",mappingId)
                .params("submitId",p_id)
                .params("isfirstReport",isfirstReport)
                ;
        for (DialogBean bean: dialogList){
            params.params(bean.getSubmitName(),bean.getResult());
        }
                params.execute(new StringLoadingCallback(this,mPullToRefreshScrollView,search) {
                    @Override
                    public void onResponse(boolean isFromCache, String result, Request request, @Nullable Response response) {
                        Log.i("test", "报工已领取列表: " + result);
                        if (type == 1) {
                            list.clear();
                        }
                        JSONObject jsonObj = JSON.parseObject(result);
                        int code = jsonObj.getInteger("code");ViewUtil.lagout(code,getApplicationContext());
                        if (code == 0) {
                            JSONObject Jpage = jsonObj.getJSONObject("page");
                            List<ReceiveSendworkOrderDto> jsonArray = new ArrayList<ReceiveSendworkOrderDto>(JsonExcludeNull.parseArrayExcludeNull(Jpage.getString("list"), ReceiveSendworkOrderDto.class));
                            list.addAll(jsonArray);
                            lv.setAdapter(adapter);
                            if (list.size() == 0) {
                                mMangeNodata.setVisibility(View.VISIBLE);
                            } else {
                                mMangeNodata.setVisibility(View.GONE);
                            }
                            adapter.notifyDataSetChanged();
                            StaticsCount count = JSON.parseObject(Jpage.getString("staticsCount"), new TypeReference<StaticsCount>() {
                            });
//                            tvSelect0.setText("已领取(" + count.getCount1() + ")");
//                            tvSelect1.setText("已报工(" + count.getCount1() + ")");
//                            tvSelect2.setText("已审核(" + count.getCount2() + ")");

                            getListCount(page,type,search);getGetCount(page,type,search);
                        } else {
                            ToastUtil.error(getApplicationContext(), jsonObj.getString("msg"));
                        }

                        mPullToRefreshScrollView.onRefreshComplete();
                    }
                });
    }

    private void getList(Integer page, Integer type, String search) {
        GetRequest params = OkHttpUtils
                .get(NewBaseUrl.workshop_submit_list)
//                .params("companyId", companyId)
                .params("token", token)
                .params("key", search)
                .params("limit", NewBaseUrl.num)
                .params("page", page.toString())
                .params("auditStatus", auditStatus)
                .params("isfirstReport", isfirstReport)
                .params("sendworkId", sendworkId)
                .params("mappingId", mappingId)
                .params("id",p_id)
                ;

        for (DialogBean bean: dialogList){
            params.params(bean.getSubmitName(),bean.getResult());
        }
        params        .execute(new StringLoadingCallback(this,mPullToRefreshScrollView,search) {
                    @Override
                    public void onResponse(boolean isFromCache, String result, Request request, @Nullable Response response) {
                        Log.i("test", "报工计划列表: " + result);
                        if (type == 1) {
                            list2.clear();
                        }
                        JSONObject jsonObj = JSON.parseObject(result);
                        int code = jsonObj.getInteger("code");ViewUtil.lagout(code,getApplicationContext());
                        if (code == 0) {
                            JSONObject Jpage = jsonObj.getJSONObject("page");

                            List<CombineEntity> jsonArray = new ArrayList<CombineEntity>(JsonExcludeNull.parseArrayExcludeNull(Jpage.getString("list"), CombineEntity.class));
                            list2.addAll(jsonArray);

                            if (list2.size() == 0) {
                                mMangeNodata.setVisibility(View.VISIBLE);
                            } else {
                                mMangeNodata.setVisibility(View.GONE);
                            }
                            StaticsCount count = JSON.parseObject(Jpage.getString("staticsCount"), new TypeReference<StaticsCount>() {
                            });
//                            tvSelect0.setText("已领取(" + count.getCount0() + ")");
//                            tvSelect1.setText("已报工(" + count.getCount1() + ")");
//                            tvSelect2.setText("已审核(" + count.getCount2() + ")");
                            lv.setAdapter(adapter2);
                            getListCount(page,type,search);getGetCount(page,type,search);


                            adapter2.notifyDataSetChanged();
                        } else {
                            ToastUtil.error(getApplicationContext(), jsonObj.getString("msg"));
                        }

                        mPullToRefreshScrollView.onRefreshComplete();
                    }
                });
    }

    private void getGetCount(Integer page, Integer type, String search) {
        GetRequest params = OkHttpUtils
                .get(NewBaseUrl.workshop_get_list_queryCount)
//                .params("companyId", companyId)
                .params("token", token)
                .params("key", search)
                .params("limit", NewBaseUrl.num).params("page", page.toString())
                .params("receiveStatus", receiveStatus)
                .params("queryReportCount", "1")
                .params("sendworkId",sendworkId)
                .params("mappingId",mappingId)
                .params("submitId",p_id)
                .params("isfirstReport",isfirstReport)
                ;
        for (DialogBean bean: dialogList){
            params.params(bean.getSubmitName(),bean.getResult());
        }
        params.execute(new StringCallback() {
            @Override
            public void onResponse(boolean isFromCache, String result, Request request, @Nullable Response response) {
                Log.i("test", "报工已领取列表: " + result);

                JSONObject jsonObj = JSON.parseObject(result);
                int code = jsonObj.getInteger("code");ViewUtil.lagout(code,getApplicationContext());
                if (code == 0) {
                    JSONObject Jpage = jsonObj.getJSONObject("page");
//                    List<ReceiveSendworkOrderDto> jsonArray = new ArrayList<ReceiveSendworkOrderDto>(JsonExcludeNull.parseArrayExcludeNull(Jpage.getString("list"), ReceiveSendworkOrderDto.class));
//                    list.addAll(jsonArray);
//                    lv.setAdapter(adapter);
//                    if (list.size() == 0) {
//                        mMangeNodata.setVisibility(View.VISIBLE);
//                    } else {
//                        mMangeNodata.setVisibility(View.GONE);
//                    }
//                    adapter.notifyDataSetChanged();
                    StaticsCount count = JSON.parseObject(Jpage.getString("staticsCount"), new TypeReference<StaticsCount>() {
                    });
                    tvSelect0.setText("已领取(" + count.getCount1() + ")");
//                    tvSelect1.setText("已报工(" + count.getCount1() + ")");
//                    tvSelect2.setText("已审核(" + count.getCount2() + ")");
                }

//                else {
//                    ToastUtil.error(getApplicationContext(), jsonObj.getString("msg"));
//                }

//                mPullToRefreshScrollView.onRefreshComplete();
            }
        });
    }

    private void getListCount(Integer page, Integer type, String search) {
        GetRequest params = OkHttpUtils
                .get(NewBaseUrl.workshop_submit_list_queryCount)
//                .params("companyId", companyId)
                .params("token", token)
                .params("key", search)
                .params("limit", NewBaseUrl.num)
                .params("page", page.toString())
                .params("auditStatus", auditStatus)
                .params("isfirstReport", isfirstReport)
                .params("sendworkId", sendworkId)
                .params("mappingId", mappingId)
                .params("id",p_id)
                ;

        for (DialogBean bean: dialogList){
            params.params(bean.getSubmitName(),bean.getResult());
        }
        params        .execute(new StringCallback() {
            @Override
            public void onResponse(boolean isFromCache, String result, Request request, @Nullable Response response) {
                Log.i("test", "报工计划列表: " + result);

                JSONObject jsonObj = JSON.parseObject(result);
                int code = jsonObj.getInteger("code");ViewUtil.lagout(code,getApplicationContext());
                if (code == 0) {
                    JSONObject Jpage = jsonObj.getJSONObject("page");
//
//                    List<CombineEntity> jsonArray = new ArrayList<CombineEntity>(JsonExcludeNull.parseArrayExcludeNull(Jpage.getString("list"), CombineEntity.class));
//                    list2.addAll(jsonArray);
//
//                    if (list2.size() == 0) {
//                        mMangeNodata.setVisibility(View.VISIBLE);
//                    } else {
//                        mMangeNodata.setVisibility(View.GONE);
//                    }
                    StaticsCount count = JSON.parseObject(Jpage.getString("staticsCount"), new TypeReference<StaticsCount>() {
                    });
//                            tvSelect0.setText("已领取(" + count.getCount0() + ")");
                    tvSelect1.setText("已报工(" + count.getCount1() + ")");
                    tvSelect2.setText("已审核(" + count.getCount2() + ")");
//                    lv.setAdapter(adapter2);



                }
//                else {
//                    ToastUtil.error(getApplicationContext(), jsonObj.getString("msg"));
//                }

//                mPullToRefreshScrollView.onRefreshComplete();
            }
        });
    }

    private void setStatus(String status) {
        switch (status) {
            case "0":
                receiveStatus = "1";
                auditStatus = "";
etSearch.setHint("派工单号/品号/品名");
                tvSelect0.setTextColor(getResources().getColor(R.color.button_blue));
                tvSelect1.setTextColor(getResources().getColor(R.color.black33));
                tvSelect2.setTextColor(getResources().getColor(R.color.black33));
                ivSelect0.setBackgroundColor(getResources().getColor(R.color.button_blue));
                ivSelect1.setBackgroundColor(getResources().getColor(R.color.white));
                ivSelect2.setBackgroundColor(getResources().getColor(R.color.white));
                customer(1, 1, etSearch.getText().toString());
                rlMuti.setVisibility(View.GONE);

                break;
            case "1":
                receiveStatus = "";
                auditStatus = "0";
                etSearch.setHint("报工单号/品号/品名");

                tvSelect1.setTextColor(getResources().getColor(R.color.button_blue));
                tvSelect2.setTextColor(getResources().getColor(R.color.black33));
                tvSelect0.setTextColor(getResources().getColor(R.color.black33));
                ivSelect1.setBackgroundColor(getResources().getColor(R.color.button_blue));
                ivSelect2.setBackgroundColor(getResources().getColor(R.color.white));
                ivSelect0.setBackgroundColor(getResources().getColor(R.color.white));
                rlMuti.setVisibility(View.GONE);


                customer(1, 1, etSearch.getText().toString());
                break;
            case "2":
                receiveStatus = "";
                auditStatus = "1";
                etSearch.setHint("报工单号/品号/品名");

                tvSelect2.setTextColor(getResources().getColor(R.color.button_blue));
                tvSelect1.setTextColor(getResources().getColor(R.color.black33));
                tvSelect0.setTextColor(getResources().getColor(R.color.black33));
                ivSelect2.setBackgroundColor(getResources().getColor(R.color.button_blue));
                ivSelect1.setBackgroundColor(getResources().getColor(R.color.white));
                ivSelect0.setBackgroundColor(getResources().getColor(R.color.white));

                customer(1, 1, etSearch.getText().toString());
                rlMuti.setVisibility(View.GONE);

                break;

        }
    }

    public void setSelect(String select) {
        switch (select) {
//
            case "0":
                isfirstReport = "1";
                setStatus("1");
                break;
            case "1":
                isfirstReport = "0";
                setStatus("1");
                break;
            case "2":
                isfirstReport = "1";
                setStatus("2");
                break;
            case "3":
                isfirstReport = "0";

                setStatus("2");
                break;

        }
    }

    @OnClick({R.id.tv_select,R.id.rl_select0, R.id.rl_select1, R.id.rl_select2})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.rl_select0:
                setStatus("0");
                break;
            case R.id.rl_select1:
                setStatus("1");
                break;
            case R.id.rl_select2:
                setStatus("2");
                break;
            case R.id.tv_select:
                showDialog();
                break;
        }
    }

    public void showDialog() {
        if (dialog == null) {
            dialogList.clear();
            dialogList.add( new DialogBean("productId","品名", 1, BaseNetUtil.base(this, NetworkEnum.PRODUCT, mCompanyId)));
            dialogList.add( new DialogBean("beltlineId","产线名称", 1, BaseNetUtil.base(this, NetworkEnum.BELTLINE, mCompanyId)));


            dialog = DialogUtils.selectNewDialog(this, dialogList, new ActionCallback() {
                @Override
                public void run() {
                    customer(1, 1, "");
                    dialog.dismiss();

                }
            });
            dialog.show();
        } else {
            dialog.show();
        }
    }
}
